const fs = require('fs')
const path = require('path')
const http = require('http')
const qs = require('querystring')
const server = http.createServer()
server.on('request', (req, res) => {
    //省市区接口
    if (req.url === '/api/city') {
      fs.readFile(path.join(__dirname,'data/city.json'),(err,data) =>{
        if (err) return console.log(err)
        res.setHeader('Content-Type', 'application/json;charset=utf-8')
        
        res.end(data[i].provinceName.toString())
      })
    } else if(req.url.startsWith('/api/city')){
    const paramStr = req.url.split('?')[1]

    res.setHeader('Content-Type', 'text/html;charset=utf-8')
    res.end()
    }
    else {
        res.setHeader('Content-Type', 'text/html;charset=utf-8')
        res.end('你要访问的资源路径不存在')
    }

})

server.listen(3000, () => {
    console.log('Web 服务启动了')
})